package Demo02.Exception;

import java.io.FileNotFoundException;
import java.io.IOException;

public class Demo02TryCatchFinally {
    public static void main(String[] args) {
        try {
            readFile("c:\\a.txt");
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            //无论是否出现异常，都会执行
            System.out.println("资源释放");
        }
    }

    public static void readFile(String fileName) throws FileNotFoundException, IOException {
//        if(!fileName.equals("c:\\a.txt")){
//            throw new FileNotFoundException("传递的文件路径不是c:\\a.txt");
//        }
        if(!fileName.endsWith(".txt")){
            throw new IOException("文件的后缀名不对");
        }
        System.out.println("路径没问题，读取文件");
    }
}
